﻿
// GDIPlusEasyTestView.cpp: CGDIPlusEasyTestView 类的实现
//

#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义，并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "GDIPlusEasyTest.h"
#endif

#include "GDIPlusEasyTestDoc.h"
#include "GDIPlusEasyTestView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CGDIPlusEasyTestView

IMPLEMENT_DYNCREATE(CGDIPlusEasyTestView, CView)

BEGIN_MESSAGE_MAP(CGDIPlusEasyTestView, CView)
	// 标准打印命令
	ON_COMMAND(ID_FILE_PRINT, &CGDIPlusEasyTestView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CGDIPlusEasyTestView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CGDIPlusEasyTestView::OnFilePrintPreview)
	ON_COMMAND(ID_RECTANGLE, &CGDIPlusEasyTestView::OnRectangle)
	ON_COMMAND(ID_TRANSLATE, &CGDIPlusEasyTestView::OnTranslate)
	ON_COMMAND(ID_ROTATE, &CGDIPlusEasyTestView::OnRotate)
	ON_COMMAND(ID_SCALE, &CGDIPlusEasyTestView::OnScale)
END_MESSAGE_MAP()

// CGDIPlusEasyTestView 构造/析构

CGDIPlusEasyTestView::CGDIPlusEasyTestView() noexcept
{
	// TODO: 在此处添加构造代码
	m_nDrawTool = -1;

}

CGDIPlusEasyTestView::~CGDIPlusEasyTestView()
{
}

BOOL CGDIPlusEasyTestView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return CView::PreCreateWindow(cs);
}

// CGDIPlusEasyTestView 绘图

void CGDIPlusEasyTestView::OnDraw(CDC* pDC)
{
	CGDIPlusEasyTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	switch (m_nDrawTool)
	{
	case DRAW_NORMAL:
	{
		Gdiplus::Graphics graphics(pDC->m_hDC);//构造 Graphics 对象
		Gdiplus::Pen m_pen(Gdiplus::Color::Blue, 2);
		Gdiplus::Rect m_rect(30, 30, 180, 120);
		graphics.DrawRectangle(&m_pen, m_rect);//绘制矩形
		break;
	}
	case DRAW_TRANSLATE:
	{
		Gdiplus::Graphics graphics(pDC->m_hDC);//构造 Graphics 对象
		Gdiplus::Pen m_pen(Gdiplus::Color::Blue, 2);
		Gdiplus::Rect m_rect(30, 30, 180, 120);
		graphics.DrawRectangle(&m_pen, m_rect);//绘制矩形

		Gdiplus::Matrix m_matrix;//单位矩形
		m_matrix.Translate(10, 20);//平移
		graphics.SetTransform(&m_matrix);//设置矩阵变换
		graphics.DrawRectangle(&m_pen, m_rect);//绘制矩形
		break;
	}
	case DRAW_ROTATE:
	{
		Gdiplus::Graphics graphics(pDC->m_hDC);//构造 Graphics 对象
		Gdiplus::Pen m_pen(Gdiplus::Color::Blue, 2);
		Gdiplus::Rect m_rect(30, 30, 180, 120);
		graphics.DrawRectangle(&m_pen, m_rect);//绘制矩形

		Gdiplus::Matrix m_matrix;//单位矩形
		m_matrix.RotateAt(20, Gdiplus::PointF(120, 75));//绕中心旋转
		graphics.SetTransform(&m_matrix);//设置矩阵变换
		graphics.DrawRectangle(&m_pen, m_rect);//绘制矩形
		break;
	}
	case DRAW_SCALE:
	{
		Gdiplus::Graphics graphics(pDC->m_hDC);//构造 Graphics 对象
		Gdiplus::Pen m_pen(Gdiplus::Color::Blue, 2);
		Gdiplus::Rect m_rect(30, 30, 180, 120);
		graphics.DrawRectangle(&m_pen, m_rect);//绘制矩形

		Gdiplus::Matrix m_matrix;//单位矩形
		m_matrix.Scale(0.3f, 0.3f);//投影变换
		graphics.SetTransform(&m_matrix);//设置矩阵变换
		graphics.DrawRectangle(&m_pen, m_rect);//绘制矩形
		break;
	}
	}	
}


// CGDIPlusEasyTestView 打印

BOOL CGDIPlusEasyTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 默认准备
	return DoPreparePrinting(pInfo);
}

void CGDIPlusEasyTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加额外的打印前进行的初始化过程
}

void CGDIPlusEasyTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加打印后进行的清理过程
}


// CGDIPlusEasyTestView 诊断

#ifdef _DEBUG
void CGDIPlusEasyTestView::AssertValid() const
{
	CView::AssertValid();
}

void CGDIPlusEasyTestView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CGDIPlusEasyTestDoc* CGDIPlusEasyTestView::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGDIPlusEasyTestDoc)));
	return (CGDIPlusEasyTestDoc*)m_pDocument;
}
#endif //_DEBUG


// CGDIPlusEasyTestView 消息处理程序
void CGDIPlusEasyTestView::OnRectangle()
{
	m_nDrawTool = DRAW_NORMAL;
	Invalidate();
}

void CGDIPlusEasyTestView::OnTranslate()
{   
	m_nDrawTool = DRAW_TRANSLATE;
	Invalidate();
}

void CGDIPlusEasyTestView::OnRotate()
{
	
	m_nDrawTool = DRAW_ROTATE;
	Invalidate();
}

void CGDIPlusEasyTestView::OnScale()
{
	m_nDrawTool = DRAW_SCALE;
	Invalidate();
}